package models.roleAndPermessions;

import play.db.ebean.Model;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.*;

/**
 * Created by wkhl on 2016/12/27.
 */
@Entity
@Table(name = "permeissions")
public class Permeission extends Model{
    public static Finder<Integer,Permeission> finder =
            new Finder<Integer,Permeission>(Integer.class, Permeission.class);
    @Id
    public  String  id;
    public  String  text;
    public  String  url;
    public  String  parent;
    public  Integer grade;
    public  String  icon;
    public  String  sign;
    @Transient
    public  List<Permeission> children =new ArrayList<Permeission>();

    public static List<Permeission> findAll(){
        return finder.findList();
    }
    public static List<List<Permeission>> findEveLevelL(){
        List<List<Permeission>> list = new ArrayList();
        for(int i=1;i<=3;i++){//权限分三个等级，查询每一个等级的权限，分别加入到list
            List<Permeission> permeissions =finder.where().eq("grade",i).findList();
            list.add(permeissions);
        }
            return list;
    }
}
